const router = require('koa-router')()

router.prefix('/users')

router.get('/', function (ctx, next) {
  const data = {
    status: 200,
    message: 'success',
    data: {
      name: 'koa-users module',
      token: '123456',
      time: new Date()
    }
  }
  ctx.body = data
})

// 添加用户
router.post('/register', async (ctx, next) => {
  const { username, password } = ctx.request.body
  const result = await Model.create({username, password})
})

// 登录
router.post('/login', async (ctx, next) => {
  const { userName, password } = ctx.request.body
  const result = await Model.find({userName, password})
})

router.get('/bar', function (ctx, next) {
  ctx.body = 'this is a users/bar response'
})

module.exports = router
